package com.orange.core.security.detail;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Getter
@Setter
@Accessors(chain = true)
public class AdminDetail extends User {

    private Integer id;
    private String token;
    private List<String> roles = new ArrayList<>();
    private List<String> permissions = new ArrayList<>();

    public AdminDetail(int id, String username, String password, Collection<? extends GrantedAuthority> authorities) {
        super(username, StrUtil.isBlank(password) ? "" : password, authorities);
        this.id = id;
    }

    @JsonCreator
    public AdminDetail(@JsonProperty(value = "id") int id,
                       @JsonProperty(value = "username") String username,
                       @JsonProperty(value = "password") String password,
                       @JsonProperty(value = "enabled") boolean enabled,
                       @JsonProperty(value = "accountNonExpired") boolean accountNonExpired,
                       @JsonProperty(value = "credentialsNonExpired") boolean credentialsNonExpired,
                       @JsonProperty(value = "accountNonLocked") boolean accountNonLocked,
                       @JsonProperty(value = "authorities") Collection<? extends GrantedAuthority> authorities) {
        super(username, StrUtil.isBlank(password) ? "" : password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.id = id;
    }
}
